package com.sys.service.impl;

import com.bhudy.base.BaseServiceImpl;
import com.sys.entity.SysCrontabType;
import com.sys.service.SysCrontabTypeService;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * @Author com.bhudy
 * @Description SysCrontabTypeService
 * @Date Mon Nov 04 14:24:19 CST 2019
 */
@Service
public class SysCrontabTypeServiceImpl extends BaseServiceImpl<SysCrontabType, Serializable> implements SysCrontabTypeService {

    /**检查状态并返回对应class*/
    @Override
    public Class checkJobClass(Long sysCrontabTypeId) throws Exception {
        SysCrontabType sysCrontabType = super.get(sysCrontabTypeId);
        if (sysCrontabType == null) {
            throw new RuntimeException("创建定时任务失败 当前crontab类型不存在");
        }
        String clzName = sysCrontabType.getJobClassName();
        if (clzName == null) {
            throw new RuntimeException("创建定时任务失败 获取当前任务类型执行对象为空 check jobClassName");
        }
        Class cls = Class.forName(clzName);

        if (cls == null) {
            throw new RuntimeException("创建定时任务失败 当前任务获取任务获取执行任务job 失败 请检查对应任务类型配置");
        }
        return cls;
    }

}
